class ChatPanel extends BasePanel {

    //聊天内容
    static chatText: any = {
        0: "你太牛了！",
        1: "哈哈，手气真好。",
        2: "快点出牌呀。",
        3: "今天真高兴。",
        4: "你放炮，我不胡！",
        5: "你家里是开银行的吧？",
        6: "不好意思，我有事要先走一步啦。",
        7: "你的牌打的太好了。",
        8: "大家好，很高兴见到各位。",
        9: "怎么又断线了，网络怎么这么差呀？",
    };

    private chatGroup: eui.Group;
    private btn_chat: eui.Button;
    private expGroup: eui.Group;
    private btn_expression: eui.Button;

    public constructor() {
        super();
        this.skinName = "ChatPanelSkin";
    }

    childrenCreated() {
        super.childrenCreated();

        for (let chatId in ChatPanel.chatText) {
            if (GameConfig.isPureness && (Number(chatId) == 3 || Number(chatId) == 12 || Number(chatId) == 13)) {
                continue;
            }

            let item: ChatItem = new ChatItem();
            this.chatGroup.addChild(item);

            item.clickey = +chatId;
            item.lab_content.text = ChatPanel.chatText[chatId];
        }

        for (let i = 1; i <= 20; i++) {
            if (GameConfig.isPureness && i == 2) {
                continue;
            }

            let img: eui.Image = new eui.Image();
            img.source = "expression" + i + ".1";
            img.name = "" + i;
            img.scaleX = img.scaleY = 0.7;
            this.expGroup.addChild(img);
            img.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onClickIcon, this);
        }

        this.btn_chat.addEventListener(egret.TouchEvent.TOUCH_TAP, this.checkChat, this);
        this.btn_expression.addEventListener(egret.TouchEvent.TOUCH_TAP, this.checkExpression, this);
    }

    private onClickIcon(e: egret.TouchEvent): void {
        if (gameManager.chatTime > 0) {
            EffectTextUtils.showTips("你发言频率太快了！", 5);
            return;
        }

        gameManager.chatTime = GameConst.Time_ChatSpace;

        let p: PlayerVo = game.player;
        let id = +e.currentTarget.name;
        gameManager.socketManager.send(25, {
            type: 4,
            expression: {id: id, uid: p.uid}
        });
        this.hide();
    }

    private checkChat(): void {
        GameSound.play('sound_btn_click');
        this.chatGroup.visible = true;
        this.expGroup.visible = false;
    }

    private checkExpression(): void {
        GameSound.play('sound_btn_click');
        this.chatGroup.visible = false;
        this.expGroup.visible = true;
    }

    show() {
        super.show();

        this.left = this.right = this.top = this.bottom = 0;
    }
}